/*
-----------------------------------------------------------------------------
This source file is part of WGE

Copyright  2008 WuYong

File Name:       
   wgeMath.cpp


Descritpion:
   The WGE math library's implemetation file


***************************************************************************/
#include "wgeMath.h"
#include "d3dx9.h"

namespace wge{

	/**help function on vectors
	@remarks
	none
	*/
	///2D Vector
	
	//used for retrun value for the follwing functions
	Vector2 tempVec2;
	Vector3 tempVec3;
	Vector4 tempVec4;

	typedef D3DXVECTOR2* LPV2;
	typedef D3DXVECTOR3* LPV3;
	typedef D3DXVECTOR4* LPV4;

	WGEINLINE Vector2
	Math::wgeVec2Add (const Vector2& lkVec, const Vector2& rkVec)
	{
		D3DXVec2Add((LPV2)&tempVec2,(LPV2)&lkVec, (LPV2)&rkVec);
		return tempVec2;
	}



	WGEINLINE Vector2
	Math::wgeVec2Subtract(const Vector2& lkVec, const Vector2& rkVec)
	{
       D3DXVec2Subtract((LPV2)&tempVec2, (LPV2)&lkVec, (LPV2)&rkVec);
	   return tempVec2;
	}

	WGEINLINE float 
	 Math::wgeVec2Length(const Vector2& vec)
	{
		return D3DXVec2Length((LPV2)&vec);
	}

	WGEINLINE float 
	Math::wgeVec2LengthSq(const Vector2& vec)
	{
		return D3DXVec2LengthSq((LPV2)&vec);
	}

	WGEINLINE float   
	Math::wgeVec2DotProduct(const Vector2& lkVec, const Vector2& rkVec)
	{
		return D3DXVec2Dot((LPV2)&lkVec, (LPV2)&rkVec);
	}

	WGEINLINE float  
	Math::wgeVec2CCW(const Vector2& lkVec, const Vector2& rkVec)
	{
		return D3DXVec2CCW((LPV2)&lkVec, (LPV2)&rkVec);
	}

	 WGEINLINE Vector2
	 Math::wgeMinimize(const Vector2& lkVec, const Vector2& rkVec)
	 {
		 D3DXVec2Minimize((LPV2)&tempVec2, (LPV2)&lkVec, (LPV2)&rkVec);
		 return tempVec2;
	 }

	 WGEINLINE Vector2
	 Math::wgeMaximize(const Vector2& lkVec, const Vector2& rkVec)
	 {
		 D3DXVec2Maximize((LPV2)&tempVec2, (LPV2)&lkVec, (LPV2)&rkVec);
		 return tempVec2;
	 }

	 WGEINLINE Vector2
	 Math::wgeVec2Lerp(const Vector2& lkVec, const Vector2& rkVec, float s)
	 {
		 D3DXVec2Lerp((LPV2)&tempVec2, (LPV2)&lkVec, (LPV2)&rkVec, s);
		 return tempVec2;
	 }

	 WGEINLINE Vector2 
	 Math::wgeVec2Normalize(const Vector2& vec)
	 {
		 D3DXVec2Normalize((LPV2)&tempVec2, (LPV2)&vec);
		 return tempVec2;
	 }

	 WGEINLINE Vector2 
	 Math::wgeVec2Hermite(const Vector2& vec1, const Vector2& T1, const Vector2& vec2, const Vector2 T2, float s)
	 {
		 D3DXVec2Hermite((LPV2)&tempVec2, (LPV2)&vec1, (LPV2)&T1, (LPV2)&vec2, (LPV2)&T2, s);
		 return tempVec2;
	 }

	 WGEINLINE Vector2
	 Math::wgeVec2CatmullRom (const Vector2& vec0, const Vector2& vec1, const Vector2& vec2, const Vector2& vec3,  float s)
	 {
		 D3DXVec2CatmullRom((LPV2)&tempVec2, (LPV2)&vec0, (LPV2)&vec1, (LPV2)&vec2, (LPV2)&vec3, s);
		 return tempVec2;
	 }
	 WGEINLINE Vector2 
	 Math::wgeVec2BaryCentric(const Vector2& vec0, const Vector2& vec1, const Vector2& vec2, const Vector2& vec3,  float f,  float g)
	 {
		 D3DXVec2BaryCentric((LPV2)&tempVec2, (LPV2)&vec1, (LPV2)&vec2, (LPV2)&vec3, f, g);
		 return tempVec2;
	 }
	// Transform (x, y, 0, 1) by matrix.
	WGEINLINE Vector4 
	Math::wgeVec2Transform  (const Vector2& vec, const Matrix& m)
	{
		 D3DXVec2Transform((LPV4)&tempVec4, (LPV2)&vec, (D3DXMATRIX*)&m);
		 return tempVec4;
	}
	// Transform (x, y, 0, 1) by matrix, project result back into w=1.
	WGEINLINE Vector2 
	Math::wgeVec2TransformCoord(const Vector2& vec, const Matrix& m)
	{
		D3DXVec2TransformCoord((LPV2)&tempVec2, (LPV2)&vec, (D3DXMATRIX*)&m);
		return tempVec2;
	}
	// Transform (x, y, 0, 0) by matrix.
	WGEINLINE Vector2 
	Math::wgeVec2TransformNormal(const Vector2& vec, const Matrix& m)
	{
		D3DXVec2TransformNormal((LPV2)&tempVec2, (LPV2)&vec, (D3DXMATRIX*)&m);
		return tempVec2;
	}


}
